﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KabiManagementWeb.Models;
namespace KabiManagementWeb.Controllers
{
    public class ExtraFeesController : Controller
    {
        KBManagementDataContext context = new KBManagementDataContext();
        SalaryFacade facade = new SalaryFacade(DBUtils.DBType.Local);
        //
        // GET: /ExtraFees/

        public ActionResult Index()
        {
            return View(context.ExtraFees);
        }

        //
        // GET: /ExtraFees/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /ExtraFees/Create

        public ActionResult Create()
        {
            GetViewData();
            return View();
        }
        public void GetViewData()
        {

            ViewData["type"] = new SelectList(context.CategoryExtraFees.ToList(), "CEF_ID", "CEF_Name");
            List<SelectListItem> items = new List<SelectListItem>();

            for (int i = 1; i <= 12; i++)
            {
                var item = new SelectListItem();
                item.Text = i.ToString();
                item.Value = i.ToString();
                items.Add(item);
            }
            ViewData["month"] = new SelectList(items, "Value", "Text");
           
        }
        //
        // POST: /ExtraFees/Create

        [HttpPost]
        public ActionResult Create(ExtraFee collection)
        {
            try
            {
               
                context.ExtraFees.InsertOnSubmit(collection);
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /ExtraFees/Edit/5

        public ActionResult Edit(int id)
        {
            GetViewData();
            return View(context.ExtraFees.Single(x => x.EF_ID == id));
        }

        //
        // POST: /ExtraFees/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, ExtraFee collection,int month,int year,int CEF_ID)
        {
            try
            {
                
                var ex = context.ExtraFees.Single(x => x.EF_ID == id);
                ex.EF_ID = collection.EF_ID;
                ex.CEF_Status = collection.CEF_Status;
                ex.CEF_ID = CEF_ID;
                ex.EF_Name = collection.EF_Name;                
                ex.EF_MONEY = collection.EF_MONEY;
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /ExtraFees/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /ExtraFees/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
